package com.qingcloud.fexecutor.controller;

import com.qingcloud.fexecutor.pojo.WebPageParam;
import com.qingcloud.fexecutor.service.WebPubAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Api(value = "页面资源相关接口", tags = "页面资源相关接口")
@RestController
@RequestMapping("/resource")
public class WebPageResourceController {

    @Resource
    private WebPubAppService webPubAppService;

    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageId", value = "页面ID",
                    required = true, dataTypeClass = Integer.class, paramType = "path", example = "1"),
            @ApiImplicitParam(name = "type", value = "应用类型 1-开发应用 2-商城应用 3-发布应用",
                    required = true, dataTypeClass = String.class, paramType = "path", example = "1"),
    })
    @ApiOperation(value = "查询页面下的所有资源", notes = "查询页面下的所有资源")
    @GetMapping("/page/{pageId}/{type}")
    public Map<String, List<WebPageParam.PageResourceDTO>> pageResource(@PathVariable("pageId") Integer pageId,
                                                                        @PathVariable("type") Integer type) {
        return webPubAppService.findPageResource(pageId);
    }

}
